<template>
  <div class="pageWrapper">
    <div class="colseBtn">
      <span class="iconfont iconicon-test"></span>
    </div>
    <div class="logo">
      <span class="iconfont iconnew"></span>
    </div>
    <AuthInput
      type="text"
      placeholder="用户名/手机号"
      :rule="/^\d{5,11}$/"
      err_message="请输入正确手机号"
      @valChange="setUsername"
    ></AuthInput>
    <AuthInput
      type="text"
      placeholder="昵称"
      :rule="/^\w{3,5}$/"
      err_message="请输入正确昵称号"
      @valChange="setNickname"
    ></AuthInput>
    <AuthInput
      type="password"
      placeholder="密码"
      :rule="/^\d{6}$/"
      err_message="请输入正确密码"
      @valChange="setPassword"
    ></AuthInput>
    <AuthBtn btnText="注册" @handleClick="register"></AuthBtn>
  </div>
</template>

<script>
// 引入
import AuthInput from "../components/AuthInput";
import AuthBtn from "../components/AuthBtn";

export default {
  data() {
    return {
      username: "",
      nickname: "",
      password: "",
    };
  },
  components: {
    AuthInput,
    AuthBtn,
  },
  methods: {
    setUsername(newUsername) {
      this.username = newUsername;
    },
    setNickname(newNickname) {
      this.nickname = newNickname;
    },
    setPassword(newPassword) {
      this.password = newPassword;
    },
    register() {
      // console.log("通知注册");
      // console.log(this.username);
      // console.log(this.nickname);
      // console.log(this.password);
      if (!this.username || !this.nickname || !this.password) {
        this.$toast.fail("请输入完整信息");
        return;
      }
      this.$axios({
        method: "post",
        url: "http://127.0.0.1:3000/register",
        data: {
          username: this.username,
          nickname: this.nickname,
          password: this.password,
        },
      }).then((res) => {
        // console.log(res.data);
        if (res.data.message == "注册成功") {
          this.$toast.success("注册成功");
        } else {
          this.$toast.fail(res.data.message);
        }
      });
    },
  },
};
</script>

<style lang="less" scoped>
.pageWrapper {
  background-image: linear-gradient(
    150deg,
    rgba(0, 106, 255, 0.925),
    rgba(255, 0, 255, 0.647)
  );
  padding: 24/360 * 100vw;
}
.iconicon-test {
  font-size: 26/360 * 100vw;
}
.logo {
  text-align: center;
}
.iconnew {
  font-size: 126/360 * 100vw;
  color: #cc3300;
}
</style>